package xrc.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 消息发送者
 */

@Service
@Slf4j
public class MQSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /*public void send(Object msg) {
        log.info("sending message : ", msg);
        rabbitTemplate.convertAndSend("fanoutExchange", "", msg);
    }

    public void send01(Object msg) {
        log.info("sending red message : " + msg);
        // 变量应与 RabbitMQDirectConfig 中的默认变量名保持一致 否则发送消息无法被获取到
        rabbitTemplate.convertAndSend("directExchange", "queue.red", msg);
    }

    public void send02(Object msg) {
        log.info("sending green message : " + msg);
        rabbitTemplate.convertAndSend("directExchange", "queue.green", msg);
    }

    public void send03(Object msg) {
        log.info("sending message received by QUEUE01: " + msg);
        rabbitTemplate.convertAndSend("topicExchange", "queue.red.message", msg);
    }

    public void send04(Object msg) {
        log.info("sending message received by QUEUE01 and QUEUE02: " + msg);
        rabbitTemplate.convertAndSend("topicExchange", "MESSAGE.queue.green.message", msg);
    }*/

    // 发送秒杀信息
    public void sendSeckillMessage(String message) {
        log.info("sending message : " + message);
        rabbitTemplate.convertAndSend("seckillExchange", "seckill.message", message);
    }
}
